/*
 *  protocol.h
 *  Communication protocol definition. 
 */

#ifndef PROTOCOL_H
#define PROTOCOL_H

#include <string>
#include "message.h"
#include "socket.h"

class Protocol {

public:
    static const std::string MSG_GAME_ABORT;
    static const std::string MSG_GAME_ABORT_OK;
    static const std::string MSG_GAME_ABORT_FAIL;
    static const std::string MSG_CREATE_GAME;
    static const std::string MSG_CREATE_GAME_OK;
    static const std::string MSG_CREATE_GAME_FAIL;
    static const std::string MSG_JOIN_GAME;
    static const std::string MSG_JOIN_GAME_OK;
    static const std::string MSG_JOIN_GAME_FAIL;
    static const std::string MSG_PLAYER_JOINED;
    static const std::string MSG_PLAYER_DISSEVERED;
    static const std::string MSG_START_GAME;
    static const std::string MSG_START_GAME_OK;
    static const std::string MSG_START_GAME_FAIL;
    static const std::string MSG_END_GAME;
    static const std::string MSG_LIST_GAMES;
    static const std::string MSG_LIST_CAMPAIGNS;
    static const std::string MSG_TEXT;
    static const std::string MSG_DISCONNECTED;
    static const std::string MSG_INFO;
    Protocol();
    ~Protocol();
    void sendMessage(Message* msg, Socket& sock);
    Message* recvMessage(Socket& sock);
private:
    static const char CODE_EOT = '\004';    //End of Transmission
    static const int BUFFSIZE = 50;
    void encode(char* buf, int len);
    void decode(char* buf, int len);
};

#endif  //PROTOCOL_H

//{+}

